package com.ogawa.base.base

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.LogUtils

abstract class BaseFragment : Fragment() {
    var TAG = javaClass.simpleName
    private var viewRoot: View? = null

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        LogUtils.d(TAG,"onCreateView")
        if (viewRoot == null) {
            viewRoot = inflater.inflate(getLayoutId(), container, false)
        }
        return viewRoot
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        LogUtils.d(TAG,"onViewCreated")
        viewRoot?.let { initView(it) }
    }

    abstract fun getLayoutId(): Int

    abstract fun initView(rootView: View)



    override fun onResume() {
        super.onResume()
        LogUtils.d(TAG,"onResume")
    }

    override fun onPause() {
        super.onPause()
        LogUtils.d(TAG,"onPause")
    }

    override fun onStart() {
        super.onStart()
        LogUtils.d(TAG,"onStart")
    }

    override fun onStop() {
        super.onStop()
        LogUtils.d(TAG,"onStop")
    }
}